<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:composite="http://java.sun.com/jsf/composite"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:s="http://www.suricattus.com.br/jsf/ui"
	xmlns:sf="http://www.suricattus.com.br/jsf/fn"
	xmlns:ec="http://www.b2cexpress.com.br/ecommerce">    	

	<composite:interface>	
	
		<composite:attribute name="updateId" />
		
		<composite:attribute name="property" required="true"  />
	
    	<composite:attribute name="actionUpdateId" />
    	
	</composite:interface>	
	
	<composite:implementation>
	
		<h:form id="modalPesquisaRevendedorForm" styleClass="form-horizontal">
			
			<p:dialog id="revendedorPanel" header="#{labels['label.selecionar.revendedor']}" widgetVar="_dgRevendedor" resizable="false" draggable="false" width="650" height="400" modal="true" closable="false">
			  
				<p:fieldset>
									
					<ec:field id="cnpj" fieldId="cnpjField" label="#{labels['label.cnpj']}" required="false">
						<p:inputMask id="cnpjField" value="#{selecionarRevendedorController.filtroRevendedor.cnpj}" >
							<s:cnpj />
						</p:inputMask>
					</ec:field>
								
					<ec:field id="nomeFantasia" fieldId="nomeFantasiaField" label="#{labels['label.nome.fantasia']}" required="false">
						<p:inputText id="nomeFantasiaField" value="#{selecionarRevendedorController.filtroRevendedor.nomeFantasia}" label="#{labels['label.nome.fantasia']}" maxlength="100"/>
					</ec:field>
					
					<ec:field id="razaoSocial" fieldId="razaoSocialField" label="#{labels['label.razao.social']}" required="false">
						<p:inputText id="razaoSocialField" value="#{selecionarRevendedorController.filtroRevendedor.razaoSocial}" label="#{labels['label.razao.social']}" maxlength="100"/>
					</ec:field>
					
					<br/>
							
					<div class="controls">
								
						<p:commandLink id="pesquisarButton" action="#{selecionarRevendedorController.pesquisar}" styleClass="btn btn-primary" update="resultadoPesquisa" process="@form">
							<i class="icon-search icon-white"></i>
							<h:outputText value=" #{labels['botao.pesquisar']}"/>
						</p:commandLink>
						<p:defaultCommand target="pesquisarButton" />
						
						<p:spacer width="20px" />

						<p:commandLink id="cancelarButton"
							styleClass="btn btn-primary"
							action="#{selecionarRevendedorController.limparPesquisa}"
							immediate="true"
							update="resultadoPesquisa"
							onclick="_dgRevendedor.hide()">
							<i class="icon-remove icon-white"></i>
							<h:outputText value=" #{labels['botao.fechar']}" />
						</p:commandLink>						
									
					</div>
									
				</p:fieldset> 
				
				<br/>
								
				<p:fieldset id="resultadoPesquisa" >
					
					<h:panelGroup rendered="#{!facesContext.validationFailed and selecionarRevendedorController.revendedores != null}">
						<p:fieldset rendered="#{empty selecionarRevendedorController.revendedores}">
							<h2><small><h:outputText value="#{messages['msgP006']}" /></small></h2>
						</p:fieldset>
						
						<p:fieldset rendered="#{not empty selecionarRevendedorController.revendedores}">
						
			   				<p:dataTable id="dtRevendedor" var="_item" value="#{selecionarRevendedorController.revendedores}" tableStyleClass="table table-striped" paginatorPosition="bottom" paginator="true" paginatorAlwaysVisible="false">
			   				  
								<p:column style="width: 15%">
									<f:facet name="header">
										<h:outputText value="#{labels['label.cnpj']}" />
									</f:facet>
									<h:outputText value="#{_item.cnpj}" converter="br.com.suricattus.surispring.jsf.converter.CnpjConverter" />
								</p:column>
				
								<p:column style="width: 40%">
									<f:facet name="header">
										<h:outputText value="#{labels['label.nome.fantasia']}" />
									</f:facet>
									<h:outputText value="#{_item.nomeFantasia}" />
								</p:column>
								
								<p:column style="width: 35%">
									<f:facet name="header">
										<h:outputText value="#{labels['label.razao.social']}" />
									</f:facet>
									<h:outputText value="#{_item.razaoSocial}" />
								</p:column>
			        			
								<p:column style="width:40px;text-align: center;" >
								
									<f:facet name="header">
										<h:outputText value="Selecionar" />
									</f:facet>
									
									<p:commandLink id="selecionarButton" actionListener="#{selecionarRevendedorController.limparPesquisa}" oncomplete="_dgRevendedor.hide()" update="#{cc.attrs.actionUpdateId}" process="@this">
										<i class="icon-plus"></i>
										<f:setPropertyActionListener target="#{cc.attrs.property}" value="#{_item}" /> 
									</p:commandLink>
									
								</p:column>
								        			
							</p:dataTable>	
						</p:fieldset>	
					</h:panelGroup>						
				</p:fieldset> 														
			</p:dialog> 

		</h:form>
	
	</composite:implementation>	
	
</html>	
